<?php

use App\Http\Controllers\Api\Common\AdvController;
use App\Http\Controllers\Api\Common\AreaController;
use App\Http\Controllers\Api\Common\EpidemicController;
use App\Http\Controllers\Api\Common\UploadController;
use App\Http\Controllers\Api\Common\WeatherController;
use App\Http\Controllers\Api\Common\WeiXinController;
use App\Http\Controllers\Api\Orders\OrdersController;
use App\Http\Controllers\Api\Orders\PaymentController;
use App\Http\Controllers\Api\Orders\PlaneOrdersController;
use App\Http\Controllers\Api\Orders\SnapTaskController;
use App\Http\Controllers\Api\Orders\TrainOrdersController;
use App\Http\Controllers\Api\Passengers\PassengerController;
use App\Http\Controllers\Api\Plane\FlightCallbackController;
use App\Http\Controllers\Api\Plane\PlaneChangePriceController;
use App\Http\Controllers\Api\Plane\PlaneController;
use App\Http\Controllers\Api\Train\CallbackController;
use App\Http\Controllers\Api\Train\IssueController;
use App\Http\Controllers\Api\Train\ScreenController;
use App\Http\Controllers\Api\Train\TicketController;
use App\Http\Controllers\Api\Train\TrainController;
use App\Http\Controllers\Api\Train\Trip\InviteController;
use App\Http\Controllers\Api\Train\Trip\SnapInviteController;
use App\Http\Controllers\Api\Trip\HistoryController;
use App\Http\Controllers\Api\User\UserController;
use App\Http\Controllers\Api\User\Wechat\AuthController;
use Illuminate\Support\Facades\Route;
use \App\Http\Controllers\Api\Scenic\ScenicController;
use \App\Http\Controllers\Api\Scenic\ScenicTicketController;


/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

/////////////////// TODO ///////////////////////////
//Route::middleware([])->prefix('user')->group(function ($router){
//    $router->post('scenic/order',[ScenicOrdersController::class, 'book']);
//    $router->post('scenic/order/refund_apply',[ScenicOrdersController::class, 'refund_apply']);
//    $router->put('scenic/order/cancel',[ScenicOrdersController::class, 'cancel_order']);
//    $router->delete('scenic/order',[ScenicOrdersController::class, 'delete']);
//    $router->get('scenic/order/pay_info',[ScenicOrdersController::class, 'pay_info']);
//    $router->get('scenic/orders',[ScenicOrdersController::class, 'lists']);
//});
//
Route::middleware(['app.verify', 'header.verify'])->group(function ($router){
    $router->post('common/location', [AreaController::class, 'location']);
    $router->get('scenic_spot/recommend',[ScenicController::class, 'recommend']);
    $router->get('scenic_spot/popular',[ScenicController::class, 'popular']);
    $router->get('scenic_spot/list',[ScenicController::class, 'list']);
    $router->post('scenic_spot/search',[ScenicController::class, 'search']);
    $router->get('scenic_spot/tickets',[ScenicTicketController::class, 'tickets']);
    $router->get('scenic_spot/ticket',[ScenicTicketController::class, 'ticket']);
    $router->get('scenic_spot/test',[ScenicController::class, 'test']);
    $router->get('scenic_spot/{id}',[ScenicController::class, 'show']);
});
// TODO end




Route::middleware(['app.verify', 'header.verify'])->group(function ($route) {
    // 广告
    Route::get("/common/adv", [AdvController::class, 'list']);
    // 定位
    Route::get("/common/location", [AreaController::class, 'location']);
    // 天气
    Route::get("/common/weather", [WeatherController::class, 'weather']);

    // 防疫政策
    Route::any("/epidemic/policy", [EpidemicController::class, 'policy']);

    // 火车票查询
    Route::post('/train/ticket/query', [TicketController::class, 'query']);
    // 中转
    Route::post('/train/ticket/transfer', [TicketController::class, 'transfer']);
    // 中转详情
    Route::get('/train/ticket/transfer/detail', [TicketController::class, 'transfer_detail']);
    // 大屏到站
    Route::get('/train/screen/arriving', [ScreenController::class, 'arriving']);
    // 大屏候车
    Route::get('/train/screen/waiting', [ScreenController::class, 'waiting']);
    // 经停点
    Route::post('/train/passpoints', [TrainController::class, 'pass_points']);
    // 火车票查询
    // 查询某车次余票
    Route::post('/train/ticket/queryByTrain', [TicketController::class, 'queryByTrain']);
    // 查询车次坐席余票
    Route::post('/train/ticket/stocks', [TicketController::class, 'stocks']);
    Route::any('/broadcasting/auth', [UserController::class, 'broadcast_auth']);

    /************** 飞机***************/
    //机票查询
    $route->post('/plane/ticket/query', [PlaneController::class, 'ticket_query']);
    $route->post('/plane/ticket/price', [PlaneController::class, 'ticket_price']);
    $route->match(['get', 'post'], '/plane/vendor/rules', [PlaneController::class, 'rules']);
    $route->any('/plane/price/calendar', [PlaneController::class, 'price_calendar']);
    //航班舒适度
//    $route->post('/plane/flight/comfort', [PlaneController::class, 'comfort']);
    /************** 飞机***************/

    $route->middleware(['user.verify'])->group(function ($route) {
        // 上传
        $route->post("/common/upload", [UploadController::class, 'upload']);
        // 历史
        $route->get('/train/station/history', [HistoryController::class, 'list']);
        $route->delete('/train/station/history', [HistoryController::class, 'delete']);
        $route->get('/plane/airport/history', [HistoryController::class, 'airport_list']);
        $route->delete('/plane/airport/history', [HistoryController::class, 'airport_delete']);
        /***
         * 乘客
         */
        // 乘客列表
        $route->get('/common/passengers', [PassengerController::class, 'list']);
        // 默认乘客
        $route->get('/common/passengers/default', [PassengerController::class, 'defaults']);
        // 改签时,可选择的乘客
        $route->get('/user/train/orders/passengers', [TrainOrdersController::class, 'order_passengers']);
        // 新增乘客
        $route->post('/user/passenger', [PassengerController::class, 'store']);
        // 修改乘客信息
        $route->put('/user/passenger/{passenger_id}', [PassengerController::class, 'update']);
        // 乘客详情
        $route->get('/user/passenger/{passenger_id}', [PassengerController::class, 'show']);
        // 删除乘客
        $route->delete('/user/passenger/{passenger_id}', [PassengerController::class, 'delete']);
        /**
         * 订单
         */
        // 全部订单
        $route->get('/user/all/orders', [OrdersController::class, 'all_orders']);
        $route->get('/user/all/orders/index', [OrdersController::class, 'index_query']);
        // 下单
        $route->post('/user/trip/order', [OrdersController::class, 'book']);
        $route->post('/user/trip/order/before_book_price_details', [OrdersController::class, 'before_book_price_details']);
        // 火车票抢票
        $route->post('/user/train/snap', [TrainOrdersController::class, 'snap_up']);
        $route->get('/user/train/snap/dates', [TrainOrdersController::class, 'snap_dates']);
        $route->post('/user/train/snap/seats', [TrainOrdersController::class, 'snap_seats']);
        $route->post('/user/train/snap/before_data', [TrainOrdersController::class, 'snap_before_data']);
        // 助力邀请
        $route->get('/user/train/snap/invite_info', [SnapInviteController::class, 'invite']);
        // 加速助力
        $route->post('/user/train/snap/assist', [SnapInviteController::class, 'assist']);
        // 火车票订单
        $route->get('/user/train/orders', [TrainOrdersController::class, 'train_orders']);
        $route->get('/user/train/issues', [IssueController::class, 'issues']);
        $route->post('/user/train/issue', [IssueController::class, 'issue']);
        // 订单详情
        $route->get('/user/train/order', [TrainOrdersController::class, 'order_info']);
        // 抢票任务详情
        $route->get('/user/train/snap_task', [SnapTaskController::class, 'task_info']);
        // 编辑抢票任务
        $route->put('/user/train/snap_task', [SnapTaskController::class, 'edit_task']);
        $route->put('/user/train/snap/auto_ticket_switch', [SnapTaskController::class, 'auto_ticket_switch']);
        $route->post('/user/train/snap/ticket_confirm', [SnapTaskController::class, 'ticket_confirm']);
        // 取消抢票任务
        $route->put('/user/train/snap/cancel', [SnapTaskController::class, 'cancel']);
        // 订单支付详情
        $route->get('/user/train/order/pay_info', [PaymentController::class, 'pay_info']);
        $route->get('/user/train/snap/pay_info', [PaymentController::class, 'snap_task_pay_info']);
        $route->get('/user/train/snap_upgrade/pay_info', [PaymentController::class, 'snap_task_high_level_pay_info']);
        // 订单退款金额小于0 支付详情
        $route->get('/user/train/order/refund_pay_info', [PaymentController::class, 'refund_pay_info']);
        // 取消订单
        $route->put('/user/train/order/cancel', [TrainOrdersController::class, 'cancel']);
        $route->put('/user/train/snap/cancel', [SnapTaskController::class, 'cancel']);
        // 删除订单
        $route->delete('/user/train/order', [TrainOrdersController::class, 'delete']);
        // 改签
        $route->put('/user/train/order/change', [TrainOrdersController::class, 'change']);
        // 改签提交前 计算的价格明细
        $route->post('/user/train/order/before_change_price_details', [TrainOrdersController::class, 'before_change_price_details']);
        // 中转订单详情
        $route->get('/user/train/order/transfer', [TrainOrdersController::class, 'transfer']);
        // 发起退款
        $route->put('/user/train/order/refund', [TrainOrdersController::class, 'refund']);
        // 退款详情
        $route->get('/user/train/order/refund', [TrainOrdersController::class, 'refund_info']);
        // 退款前说明
        $route->get('/user/train/order/before_refund_desc', [TrainOrdersController::class, 'before_refund_desc']);
        /**
         * 分享
         */
        //出行邀请信息
        $route->get('/user/train/trip/invite_info', [InviteController::class, 'invite_info']);
        // 邀请详情(点解卡片进入)
        $route->get('/user/train/trip/invite_info/{invite_id}', [InviteController::class, 'invite_detail']);
        //加入行程邀请
        $route->post('/user/train/trip/invite/{invite_id}', [InviteController::class, 'join']);

        /**********
         *
         *  飞机订单
         */

        $route->post('/plane/before/book', [PlaneController::class, 'before_book']);
        $route->get('/plane/before/refund', [PlaneOrdersController::class, 'before_refund']);
        $route->post('/user/plane/order', [PlaneOrdersController::class, 'book']);
        $route->post('/user/plane/order/refund', [PlaneOrdersController::class, 'refund']);
        // 退款详情
        $route->get('/user/plane/order/refund', [PlaneOrdersController::class, 'refund_info']);
        $route->get('/user/plane/order/pay_info', [PaymentController::class, 'plane_pay_info']);
        $route->get('/user/plane/orders', [PlaneOrdersController::class, 'plane_orders']);
        $route->get('/user/plane/order', [PlaneOrdersController::class, 'order_info']);
        $route->post('/plane/before/change', [PlaneOrdersController::class, 'before_change']);
        $route->post('/user/plane/order/change_apply', [PlaneOrdersController::class, 'change_apply']);
        $route->put('/user/plane/order/cancel', [PlaneOrdersController::class, 'cancel']);
        $route->delete('/user/plane/order', [PlaneOrdersController::class, 'delete']);
    });
    // 订单行程分享
    $route->get('/user/train/order/share_info', [TrainOrdersController::class, 'share_info']);
    // 热门站点
    Route::get('/train/station/hot', [HistoryController::class, 'hot']);
    Route::get('/plane/airport/hot', [HistoryController::class, 'airport_hot']);
    Route::get('/plane/cities/hot', [HistoryController::class, 'airport_cities_hot']);
    // 登录
    Route::post('/wechat/miniapp/login', [AuthController::class, 'miniapp_login']);
    Route::match(['get', 'post'], '/wechat/miniapp/phone', [AuthController::class, 'miniapp_mobile']);
    Route::post('/user/phone', [UserController::class, 'phone']);
});
Route::any('/train/{source}/callback', [CallbackController::class, 'callback'])->whereIn('source', ['piaochi']);
Route::any('/payment/{source}/callback', [PaymentController::class, 'callback'])->whereIn('source', ['wechat']);
Route::any('/weixin/{source}/callback', [WeiXinController::class, 'callback'])->whereIn('source', ['official']);
Route::any('/{source}/{business}/callback', [FlightCallbackController::class, 'callback'])->whereIn('source', ['book51', 'qunar']);
Route::match(['get', 'post'], '/wechat/official/redirect', [AuthController::class, 'official_redirect']);
Route::match(['get', 'post'], '/wechat/official/login', [AuthController::class, 'official_login']);

Route::prefix('common/area')->group(function ($router) {
    $router->get('/provinces', [AreaController::class, 'provinces']);
});

Route::post('/plane/flight/comfort', [PlaneController::class, 'comfort']);

// 定位
Route::get("/common/location", [AreaController::class, 'location']);

Route::prefix('admin')->group(function ($router) {
    // 改签价格待确认价格回填
    $router->put('/plane/order/change_price/refill', [PlaneChangePriceController::class, 'refill_price']);
});
Route::match(['get', 'post'], '/wechat/official/login', [AuthController::class, 'official_login']);
